package com.company.clientscard.server.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.company.clientscard.server.dao.GeneralDao;
import com.company.clientscard.server.domain.Client;

public class ClientService {

	private GeneralDao dao;

	@Required
	public void setDao(GeneralDao dao) {
		this.dao = dao;
	}

	@Transactional
	public void save(Client client) {
		dao.save(client);
	}

	@Transactional(readOnly = true)
	public Client findById(Long id) {
		return (Client) dao.findById(Client.class, id);
	}

	@Transactional
	public Client update(Client client) {
		dao.update(client);
		return (Client) dao.findById(client.getClass(), client.getId());
	}

	@Transactional(readOnly = true)
	public List<Client> findAll(Class<Client> clazz) {
		return dao.findAll(clazz);
	}

	@Transactional(readOnly = true)
	public List<Client> findAll(Class<Client> clazz, int firstRow,
			int numberOfRows) {
		return dao.findAll(clazz, firstRow, numberOfRows);
	}

	@Transactional(readOnly = true)
	public List<Client> findWithParam(Class<Client> clazz, String paramName,
			Object param) {
		return dao.findWithParam(clazz, paramName, param);
	}
}
